www.mxdraw.com
内容索引主面
前一个向上下一个
IMxDrawDatabase::Wblock 方法

把一堆对象,输出到一个新的Database中。

IDL
[helpstring("method Wblock")]
HRESULT Wblock([in] IMxDrawResbuf* aryId, [in] IMxDrawPoint* basePoint, [out] IMxDrawIdMapping** ppIdMapping, [out,retval] IMxDrawDatabase** ppDatabase);
参数 
说明 
[in] IMxDrawResbuf* aryId 
对象的id. 
[in] IMxDrawPoint* basePoint 
图块的插入基点 
[out] IMxDrawIdMapping** ppIdMapping 
返回新的对象id与老对象id对照表 
[out,retval] IMxDrawDatabase** ppDatabase 
成功返回新的Database对象。 

成功返回新的Database对象。

例如: C# 选择对象,输出块文件

        private void ToDWG()
        {
            MxDrawSelectionSet ss = new MxDrawSelectionSet();
            ss.Select(MCAD_McSelect.mcSelectionSetUserSelect, null, null, null);

            MxDrawResbuf param = new MxDrawResbuf();

            List<Int64> aryId = new List<Int64>();
            for (Int32 i = 0; i < ss.Count; i++)
            {
                MxDrawEntity ent = ss.Item(i);
                if (ent != null)
                {
                    param.AddObjectId(ent.ObjectID);
                    aryId.Add(ent.ObjectID);
                    ent.Close();
                }
            }
            //  计算新的图块的插入基点,把所实体外包的中点做为插入基点。

            MxDrawDatabase curDatabase = (MxDrawDatabase)axMxDrawX1.GetDatabase();

            double dMinX = 0, dMinY = 0, dMaxX = 0, dMaxY = 0;
            bool isFirstEnt = true;
            for (int l = 0; l < aryId.Count; l++)
            {
                MxDrawMcDbObject pObj = curDatabase.ObjectIdToObject(aryId[l]);
                if (pObj == null)
                    continue;

                MxDrawEntity pEnt = (MxDrawEntity)pObj;
                if (pEnt == null)
                    continue;


                MxDrawPoint pt1Ob, pt2Ob;
                pEnt.GetBoundingBox(out pt1Ob, out pt2Ob);

                MxDrawPoint minPt = (MxDrawPoint)pt1Ob;
                MxDrawPoint maxPt = (MxDrawPoint)pt2Ob;

                if (minPt != null && maxPt != null)
                {
                    if(isFirstEnt)
                    {
                        dMinX = minPt.x;
                        dMinY = minPt.y;
                        dMaxX = maxPt.x;
                        dMaxY = maxPt.y;
                        isFirstEnt = false;
                    }
                    else
                    {
                        if (dMinX > minPt.x)
                            dMinX = minPt.x;

                        if (dMinY > minPt.y)
                            dMinY = minPt.y;

                        if (dMaxX < maxPt.x)
                            dMaxX = maxPt.x;

                        if (dMaxY < maxPt.y)
                            dMaxY = maxPt.y;
                    }
                }   
            }

            if(isFirstEnt)
            {
                // 没有实体
                return;
            }

            MxDrawPoint pos = new MxDrawPoint();
            pos.x = dMinX + (dMaxX - dMinX) / 2.0;
            pos.y = dMinY + (dMaxY - dMinY) / 2.0;

            //
            MxDrawIdMapping idMap;
    
            MxDrawDatabase newDatabase = curDatabase.Wblock(param,pos,out idMap);
            if(newDatabase == null)
                return;

            // 保存为dwg文件。

            if (newDatabase.SaveAs("G:\wblock.dwg", 1, null))
            {
                MessageBox.Show("Ok");
            }
            else
            {
                MessageBox.Show("Failed");
            }
        }
Copyright (c) 2010. All rights reserved.
你认为该帮助怎么样? 发送反馈信息!